package com.github.tetrisgame.ui.view;

import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.graphics.RectF;
import android.util.AttributeSet;
import android.view.View;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;

import com.github.tetrisgame.utils.UIUtils;

public class AnimationView extends View {
    private final int radius = UIUtils.dp2px(30);
    Paint paint = new Paint(Paint.ANTI_ALIAS_FLAG);
    private int angel1 = 30;
    private int centerX = 10 * radius;
    private int angel2 = -30;
    private RectF rectF;

    public AnimationView(Context context) {
        super(context);
        init();
    }

    public AnimationView(Context context, @Nullable AttributeSet attrs) {
        super(context, attrs);
        init();
    }

    public AnimationView(Context context, @Nullable AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
        init();
    }

    public int getCenterX() {
        return centerX;
    }

    public void setCenterX(int centerX) {
        this.centerX = centerX;
        invalidate();
    }

    public int getAngel1() {
        return angel1;
    }

    public void setAngel1(int angel1) {
        this.angel1 = angel1;
        invalidate();
    }

    public int getAngel2() {
        return angel2;
    }

    public void setAngel2(int angel2) {
        this.angel2 = angel2;
        invalidate();
    }

    public void init() {
        paint.setStyle(Paint.Style.FILL);
        paint.setColor(Color.parseColor("#889688FF"));
        rectF = new RectF();
    }

    @Override
    protected void onDraw(@NonNull Canvas canvas) {
        rectF.set(0, 0, 6 * radius, 6 * radius);
        canvas.drawArc(rectF, angel1, 180 - angel1, true, paint);
        canvas.drawArc(rectF, angel2, -180 - angel2, true, paint);
        canvas.drawCircle(centerX, 3 * radius, radius, paint);
    }
}
